package org.news.dao.repository.impl;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.news.beans.Users;
import org.news.dao.repository.UsersRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Repository
@Transactional
public class UsersDao implements UsersRepository{

    @Autowired
    private SqlSessionFactory sessionFactory;
    @Override
    public Users findOneObject(Users users) {
        System.out.print(users);
        SqlSession s = sessionFactory.openSession();
        users = s.selectOne("org.news.beans.selectUsers",users);
        System.out.println(users+"PPPPPPPPPPPPPPPP");
        s.close();
        return users;
    }
    @Override
    public List<Users> findAllObject(Users users) {
        SqlSession s = sessionFactory.openSession();
        List<Users> usersList = s.selectList("org.news.beans.selectUsers");
        for ( Users u : usersList )
        System.out.println(u+"OOOOOOOOOOOOOOOOOO");
        return usersList;
    }
    @Override
    public Integer save(Users users) {
        SqlSession s = sessionFactory.openSession();
        Integer key = s.insert("org.news.beans.insertUsers",users);
        return key;
    }

    @Override
    public Integer update(Users users) {
        SqlSession s = sessionFactory.openSession();
        Integer key = s.update("org.news.beans.updateUsers",users);
        return key;
    }

    @Override
    public Integer remove(Users users) {
        SqlSession s = sessionFactory.openSession();
        Integer key = s.delete("org.news.beans.deleteUsers",users);
        return key;
    }
}
